<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>blur</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css2?family=Comic+Neue:ital,wght@0,700;1,700&display=swap" rel="stylesheet">
    <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
    <link rel = "icon" href =  "https://i.pinimg.com/originals/4a/a5/df/4aa5df83115df6c96732a2d76ccb4f1b.jpg" type = "image/x-icon"> 
    
<link rel="stylesheet" href="/css/styles.css">
 
<meta name="generator" content="Hexo 5.4.0"></head>

  <body>
    <div class="container">
      <!-- Header -->
      <link rel = "icon" href =  "https://github.com/zhaoyu811/zhaoyu811.github.io/blob/master/css/head.png" type = "image/x-icon"> 
<nav id="nav">
  <header class="header">
    <a href="/" class="header-title">
      BLUR <i class="fa fa-fire" aria-hidden="true"></i>
    </a>
    
  </header>

  

  <div class="nav-wrapper">
    <div class="menu">
      <a href="/" class="nav-menu z-active">HOME</a>
      <a href="/about" class="nav-menu">ABOUT</a>
      <a href="/archives" class="nav-menu">ARCHIVE</a>
    </div>

    <div class="icons">
      <a target="_blank" rel="noopener" href="https://github.com/zhaoyu811" class="nav-icon" >
        <i class="fa fa-github-alt" aria-hidden="true"></i>
      </a>
      <a href="" class="nav-icon">
        <i class="fa fa-linkedin-square" aria-hidden="true"></i>
      </a>
      <a href="" class="nav-icon">
        <i class="fa fa-facebook-square" aria-hidden="true"></i>
      </a>
    </div>

    
  </div>
</nav>
    
<!-- <hr class="hr-divide-header" align="left"> -->
      <a name="top"></a>

<section class="article">  
  <h2 class="article-title">
    Shell输出九九乘法表 
  </h2>
  <p class="article-date">
    2019/11/20 
  </p>

  <hr class="hr-divide">

  <div class="article-content">
    <h1 id="Shell输出九九乘法表"><a href="#Shell输出九九乘法表" class="headerlink" title="Shell输出九九乘法表"></a>Shell输出九九乘法表</h1><h2 id="方法一"><a href="#方法一" class="headerlink" title="方法一"></a>方法一</h2><ul>
<li>源代码：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/bash</span></span><br><span class="line"><span class="meta">#</span><span class="bash">打印九九乘法表</span></span><br><span class="line"></span><br><span class="line">for((i=1; $i&lt;=9; i=$[i+1]))</span><br><span class="line">do</span><br><span class="line">	for((j=1; $j&lt;=$i; j=$[j+1]))</span><br><span class="line">	do</span><br><span class="line">		string=$string$j*$i=$[i*j]\\t</span><br><span class="line">	done</span><br><span class="line">	string=$string\\n</span><br><span class="line">done</span><br><span class="line"></span><br><span class="line">echo -e $string</span><br></pre></td></tr></table></figure>

<ul>
<li>输出：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[TTL@VM_0_17_centos ~]$ ./test.sh</span><br><span class="line">1*1=1</span><br><span class="line">1*2=2   2*2=4</span><br><span class="line">1*3=3   2*3=6   3*3=9</span><br><span class="line">1*4=4   2*4=8   3*4=12  4*4=16</span><br><span class="line">1*5=5   2*5=10  3*5=15  4*5=20  5*5=25</span><br><span class="line">1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36</span><br><span class="line">1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49</span><br><span class="line">1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64</span><br><span class="line">1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81</span><br><span class="line"></span><br><span class="line">[TTL@VM_0_17_centos ~]$ </span><br></pre></td></tr></table></figure>

<h2 id="方法二"><a href="#方法二" class="headerlink" title="方法二"></a>方法二</h2><ul>
<li>源代码：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/bash</span></span><br><span class="line"></span><br><span class="line">for i in $(seq 9)</span><br><span class="line">do  </span><br><span class="line">	for j in $(seq $i)</span><br><span class="line">	do</span><br><span class="line">		echo -n -e &quot;$i*$j=$(($i*$j))\t&quot;</span><br><span class="line">	done</span><br><span class="line">	echo -n -e &quot;\n&quot;</span><br><span class="line">done</span><br></pre></td></tr></table></figure>

<ul>
<li>输出：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[TTL@VM_0_17_centos ~]$ .&#x2F;test.sh</span><br><span class="line">1*1&#x3D;1</span><br><span class="line">2*1&#x3D;2   2*2&#x3D;4</span><br><span class="line">3*1&#x3D;3   3*2&#x3D;6   3*3&#x3D;9</span><br><span class="line">4*1&#x3D;4   4*2&#x3D;8   4*3&#x3D;12  4*4&#x3D;16</span><br><span class="line">5*1&#x3D;5   5*2&#x3D;10  5*3&#x3D;15  5*4&#x3D;20  5*5&#x3D;25</span><br><span class="line">6*1&#x3D;6   6*2&#x3D;12  6*3&#x3D;18  6*4&#x3D;24  6*5&#x3D;30  6*6&#x3D;36</span><br><span class="line">7*1&#x3D;7   7*2&#x3D;14  7*3&#x3D;21  7*4&#x3D;28  7*5&#x3D;35  7*6&#x3D;42  7*7&#x3D;49</span><br><span class="line">8*1&#x3D;8   8*2&#x3D;16  8*3&#x3D;24  8*4&#x3D;32  8*5&#x3D;40  8*6&#x3D;48  8*7&#x3D;56  8*8&#x3D;64</span><br><span class="line">9*1&#x3D;9   9*2&#x3D;18  9*3&#x3D;27  9*4&#x3D;36  9*5&#x3D;45  9*6&#x3D;54  9*7&#x3D;63  9*8&#x3D;72  9*9&#x3D;81</span><br><span class="line">[TTL@VM_0_17_centos ~]$ </span><br></pre></td></tr></table></figure>

<p>备注</p>
<ol>
<li> echo -n 表示不换行输出</li>
<li> echo -e 表示启用反斜杠 <kbd>\</kbd>转义输出，具体可 man echo 查询</li>
<li> seq  递增方式打印出数字，具体可 man seq 查询</li>
</ol>
 
    <hr class="hr-divide">
    <div class="article-footer">
      <a href="#top">back to top</a>
    </div>
  </div>

  
</section>  
      <!-- Footer -->
      <!-- <h1>This is the footer.ejs file</h1> -->

<footer class="footer">
  <p style="margin-top: 0px;">
    Powered by <a target="_blank" rel="noopener" href="https://hexo.io/">Hexo</a>
    Created by <a href="">@Qitian Lin</a>
  </p>
</footer>  
    </div>

    <!-- After footer file to store js of Bootstrap -->
    <!-- <h1>This is the after-footer ejs file</h1> -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
 
  </body>

</html>